/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.app.model;

import java.util.Date;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;
import at.socialconference.inter.model.Place;
import at.socialconference.inter.model.Talk;
import at.socialconference.inter.model.User;

/**
 * @author Patrick Ferula
 * 
 */
public class ATalk extends Talk implements Parcelable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3374205494972387774L;
	
	private AUser[] aSpeakers;
	private APlace aPlace;

	/**
	 * @param id
	 * @param title
	 * @param description
	 * @param date
	 * @param from
	 * @param to
	 * @param place
	 * @param speakers
	 */
	public ATalk(Integer id, String title, String description, Date date,
			Date from, Date to, Place place, List<User> speakers) {
		super(id, title, description, date, from, to, place, speakers);
	}

	public ATalk(Talk talk) {
		super();
		super.setId(talk.getId());
		super.setTitle(talk.getTitle());
		super.setDescription(talk.getDescription());
		super.setPlace(talk.getPlace());
		super.setDate(talk.getDate());
		super.setFrom(talk.getFrom());
		super.setTo(talk.getTo());
		super.setSpeakers(talk.getSpeakers());
		
		if(talk.getSpeakers()!=null){
			aSpeakers = new AUser[talk.getSpeakers().size()];
			for(int i=0;i<aSpeakers.length;i++){
				aSpeakers[i] = new AUser(talk.getSpeakers().get(i));
			}
		}
		if(talk.getPlace()!=null){
			aPlace = new APlace(talk.getPlace());
		}
		
	}
	
	public ATalk(Parcel in) {
		setId(in.readInt());
		setTitle(in.readString());
		setDescription(in.readString());
		setaPlace((APlace)in.readParcelable(APlace.class.getClassLoader()));
		setDate(new Date(in.readLong()));
		setFrom(new Date(in.readLong()));
		setTo(new Date(in.readLong()));
		
		Parcelable[] tmp = (Parcelable[]) in.readParcelableArray(AUser.class.getClassLoader());
		if(tmp!=null){
			aSpeakers = new AUser[tmp.length];
			for(int i=0;i<aSpeakers.length;i++){
				aSpeakers[i] = (AUser)tmp[i];
				
			}
		}
	}

	public AUser[] getaSpeakers() {
		return aSpeakers;
	}

	public void setaSpeakers(AUser[] aSpeakers) {
		this.aSpeakers = aSpeakers;
	}

	public APlace getaPlace() {
		return aPlace;
	}

	public void setaPlace(APlace aPlace) {
		this.aPlace = aPlace;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(getId());
		dest.writeString(getTitle());
		dest.writeString(getDescription());
		
		dest.writeParcelable(aPlace,1);
		dest.writeLong(getDate().getTime());
		dest.writeLong(getFrom().getTime());
		dest.writeLong(getTo().getTime());
		dest.writeParcelableArray(aSpeakers,1);
	}
	
	public static final Parcelable.Creator<ATalk> CREATOR = new Parcelable.Creator<ATalk>() 
	{ 
		public ATalk createFromParcel(Parcel in) 
		{ 
			return new ATalk(in); 
		} 

		public ATalk[] newArray(int size) 
		{ 
			return new ATalk[size]; 
		} 
	};

}
